package com.redis.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("testString")
public class RedisController {

    // 操作string  字符串   添加一个数据
    @Resource
    private RedisTemplate<String,String> redisTemplate;

    @GetMapping
    public void testAddString(){
        // 操作字符串
        redisTemplate.opsForValue().set("k1","v1");
        redisTemplate.delete("k1");// 删除key为k1的数据

        redisTemplate.delete(Arrays.asList("k1","k2"));

        // num 123 10m
        //
        redisTemplate.opsForValue().set("num","123",10, TimeUnit.MINUTES);

    }

}
